#include<cstdio>//uncle-lu
#include<vector>
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

int n, k;
int F[100010][25], G[100010][25];
int line[100010];
std::vector<int>edge[100010];

void DFS(int x, int fa)
{
	for (int j = 0; j <= k; j++) 
		F[x][j] += line[x];

	for (int i = 0; i < (int)edge[x].size(); i++) 
	{
		int v = edge[x][i];
		if(v == fa)continue;
		DFS(v, x);
		for (int j = 1; j <= k; j++) 
			F[x][j] += F[v][j-1];
	}
	return ;
}

void DP(int x, int fa)
{
	for (int i = 0; i < (int)edge[x].size(); i++) 
	{
		int v = edge[x][i];
		if(v == fa)continue;

		G[v][0] = line[v];
		for (int j = 1; j <= k; j++) 
			G[v][j] = G[x][j-1] - F[v][j-2] + F[v][j];
		DP(v, x);
	}
	return ;
}

int main()
{
	read(n);read(k);
	int x, y;
	for (int i = 1; i <= n-1; i++) 
	{
		read(x);read(y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	for (int i = 1; i <= n; i++) 
		read(line[i]);

	DFS(1, 0);

	for (int i = 0; i <= k; i++) 
		G[1][i] = F[1][i];
	
	DP(1, 0);

	for (int i = 1; i <= n; i++) 
		printf("%d\n", G[i][k]);

	return 0;
}
